def convert_to_socks5(input_file, output_file):
    """
    将IP文件中的内容转换为socks5://username:password@ip:port格式
    """
    with open(input_file, 'r') as f:
        lines = f.readlines()
    
    socks5_proxies = []
    for line in lines:
        line = line.strip()
        if not line:
            continue
            
        parts = line.split(':')
        if len(parts) == 4:
            ip, port, username, password = parts
            socks5_proxy = f"socks5://{username}:{password}@{ip}:{port}"
            socks5_proxies.append(socks5_proxy)
    
    with open(output_file, 'w') as f:
        f.write('\n'.join(socks5_proxies))
    
    print(f"转换完成！已将结果保存到 {output_file}")

if __name__ == "__main__":
    input_file = "ip.txt"
    output_file = "socks5_proxies.txt"
    convert_to_socks5(input_file, output_file) 